<template>
  <div id="background">
    <div class="container">
      <form action="">
        <div class="form">
          <div class="item">
            <label>用户名：</label>
            <div>
              <input
                type="text"
                name="username"
                v-model.trim="name"
                placeholder="请输入用户名"
              />
            </div>

            <!-- v-model把输入的值传输给name变量 -->
            <br />
          </div>
          <div class="item">
            <label>密码：</label>
            <div>
              <input
                type="password"
                name="password"
                v-model.trim="password"
                placeholder="请输入密码"
              />
            </div>
            <br />
          </div>
        </div>
      </form>
      <el-button class="button" round type="submit" @click.prevent="handlelogin"
        >登录</el-button
      >
      <!-- v-on点击按钮触发handlelogin方法 -->
      <el-button class="button" round @click.prevent="handleregister"
        >注册</el-button
      >
      <el-button class="button" round>忘记密码</el-button>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "", //姓名，用v-model绑定监听，将输入的字符串赋值给name变量
      password: "", //密码
      st: "false", //false为不保存登录
    };
  },
  methods: {
    handlelogin: function () {
      if (
        this.name === localStorage["name"] &&
        this.password === localStorage["password"]
      ) {
        this.$router.push("/HomeNea"); //如果输入的名字以及密码正确路由跳转至个人页面
      } else if (this.name === "") {
        //名字为空
        alert("用户名不为空");
      } else if (this.password === "") {
        //密码为空
        alert("密码不为空");
      } else {
        alert("账号不存在，请注册后登录"); //查无此号
      }
    },
    handleregister: function () {
      this.$router.replace("/register"); //点击注册按钮，跳转至注册页面
    },
    //点击保持登录状态触发handlesave
    handlesave: function () {
      this.st = "true"; //修改登录状态为true
      localStorage.setItem("s", this.st);
      console.log(localStorage.s);
    },
  },
};
</script>

<style scoped>
#background {
  width: 100%;
  height: 100%;
  /* background: url("../assets/bg2.jpg"); */
  background-size: 100% 100%;
  position: fixed;
  top: 0;
  left: 0;
  user-select: none;
  background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
}

.container {
  height: 300px;
  /* background: #00000090; */
  text-align: center;
  border-radius: 20px;
  margin-top: 10px;
  padding-top: 20px;
}
.container h1 {
  color: aliceblue;
  margin-left: 20px;
}
.item {
  margin-bottom: 10px;
  font-size: 20px;
  text-align: left;
  display: flex;
  align-items: center;
}
.item label {
  float: left;
  width: 5em;
  margin-right: 1em;
  text-align: right;
}

input {
  margin-left: -5px;
  padding: 4px;
  border: none;
  outline: none;
  font: normal 13px/100% Verdana, Tahoma, sans-serif;
  width: 200px;
  height: 23px;
  display: block;
  width: 100%;
  border: 0;
  padding: 10px;
  font-size: 15px;
  outline: none;
}
.button {
  position: relative;
  height: 33px;
  width: 100px;
  border-radius: 10px;
  margin-top: 18px;
  box-shadow: none;
  margin-right: 10px;
  text-align: center;
  padding: 10px;
  background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
  color: #fff;
}

.keep input {
  width: 15px;
  height: 15px;
  margin-top: 7px;
  margin-left: 10px;
  margin-right: 10px;
}
</style>
